package com.code.zjm.firstapp;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;

import java.io.Serializable;
import java.util.concurrent.ThreadPoolExecutor;

public class ThreadManager {

    private String tag = "ThreadManager";//标志
    private AsyHandler asyHandler;//异步操作
    private UiHandler uiHandler;//UI操作
    private ThreadPoolExecutor threadPoolExecutor;

    private static volatile ThreadManager threadManager = new ThreadManager();

    private ThreadManager() {
    }

    /**
     * 获取 ThreadManager 实例
     *
     * @return
     */
    public static ThreadManager getInstance() {

        if (null == threadManager) {
            synchronized (ThreadManager.class) {
                if (null == threadManager) {
                    threadManager = new ThreadManager();
                }
            }
        }
        return threadManager;
    }

    /**
     * 插入耗时长的操作
     *
     * @param tagH 标签名
     */
    public void putLongTime(final ThreadManagerCallBack threadManagerCallBack, final String tagH) {
    }

    /**
     * 插入耗时短的操作，可以更新UI，同时threadManagerCallBack执行优先于threadManagerUiCallBack
     *
     * @param threadManagerCallBack   刷新异步接口
     * @param threadManagerUiCallBack 刷新UI
     * @param tagH                    标签名
     * @param delayMillis             延时时间 毫秒
     */
    public void putShortTimeUiDelayed(ThreadManagerCallBack threadManagerCallBack,
                                      ThreadManagerUiCallBack threadManagerUiCallBack, String tagH, long delayMillis) {
    }

    /**
     * 插入耗时 的操作，可以更新UI，同时threadManagerCallBack执行优先于threadManagerUiCallBack
     *
     * @param threadManagerCallBack   刷新异步接口
     * @param threadManagerUiCallBack 刷新UI
     * @param tagH                    标签名
     */
    public void putShortTimeUi(ThreadManagerCallBack threadManagerCallBack,
                               ThreadManagerUiCallBack threadManagerUiCallBack, String tagH) {
    }

    /**
     * 插入耗时较少的操作，可以更新UI，同时threadManagerCallBack执行优先于threadManagerUiCallBack
     *
     * @param threadManagerCallBack   刷新异步接口
     * @param threadManagerUiCallBack 刷新UI
     * @param tagH                    标签名
     * @param uptimeMillis            特定时间
     */
    public void putShortTimeUiAtTime(ThreadManagerCallBack threadManagerCallBack,
                                     ThreadManagerUiCallBack threadManagerUiCallBack, String tagH, long uptimeMillis) {
    }

    /**
     * 插入耗时较少的操作，不可以更新UI
     *
     * @param threadManagerCallBack 刷新异步接口
     * @param tagH                  标签名
     * @param delayMillis           延时时间 毫秒
     */
    public void putShortTimeDelayed(ThreadManagerCallBack threadManagerCallBack, String tagH, long delayMillis) {
    }

    /**
     * 插入耗时较少的操作，不可以更新UI
     *
     * @param threadManagerCallBack 刷新异步接口
     * @param tagH                  标签名
     */
    public void putShortTime(ThreadManagerCallBack threadManagerCallBack, String tagH) {
    }

    /**
     * 插入耗时较少的操作，不可以更新UI
     *
     * @param threadManagerCallBack 刷新异步接口
     * @param tagH                  标签名
     * @param uptimeMillis          特定时间
     */
    public void putShortTimeAtTime(ThreadManagerCallBack threadManagerCallBack, String tagH, long uptimeMillis) {
    }


    /**
     * 异步操作类 AsyHandler
     */
    private class AsyHandler extends Handler {

        public AsyHandler() {
        }

        public AsyHandler(Looper looper) {
            super(looper);
        }

        public void handleMessage(Message msg) {
        }

    }

    /**
     * UI 操作类 UIHandler
     */
    private class UiHandler extends Handler {
        public UiHandler() {
        }

        public void dispatchMessage(Message msg) {
        }
    }

    private class ThreadContent implements Serializable {
        String tagH;
        int threadType;
        public static final int INCLUDE_UI = 1;
        public static final int INCLUDE_NO_UI = 0;
        ThreadManager.ThreadManagerCallBack threadManagerCallBack;
        ThreadManager.ThreadManagerUiCallBack threadManagerUiCallBack;

        private ThreadContent() {
        }

        public int getThreadType() {
            return this.threadType;
        }

        public void setThreadType(int threadType) {
            this.threadType = threadType;
        }

        public ThreadManager.ThreadManagerCallBack getThreadManagerCallBack() {
            return this.threadManagerCallBack;
        }

        public void setThreadManagerCallBack(ThreadManager.ThreadManagerCallBack threadManagerCallBack) {
            this.threadManagerCallBack = threadManagerCallBack;
        }

        public ThreadManager.ThreadManagerUiCallBack getThreadManagerUiCallBack() {
            return this.threadManagerUiCallBack;
        }

        public void setThreadManagerUiCallBack(ThreadManager.ThreadManagerUiCallBack threadManagerUiCallBack) {
            this.threadManagerUiCallBack = threadManagerUiCallBack;
        }

        public String getTagH() {
            return this.tagH;
        }

        public void setTagH(String tagH) {
            this.tagH = tagH;
        }
    }

    public ThreadPoolExecutor getThreadPoolExecutor() {
        return threadPoolExecutor;
    }

    public void setThreadPoolExecutor(ThreadPoolExecutor threadPoolExecutor) {
        this.threadPoolExecutor = threadPoolExecutor;
    }

    public static abstract interface ThreadManagerCallBack extends Serializable {
        public abstract void threadCallBack(ThreadManager.ThreadState paramThreadState);
    }

    public static abstract interface ThreadManagerUiCallBack extends Serializable {
        public abstract void threadUiCallBack(ThreadManager.ThreadState paramThreadState);
    }

    public class ThreadState implements Serializable {
        int FLAG;
    }

}
